<template>
	<view class="pics">
		<scroll-view class="left" scroll-y>
			<view class="left-item" v-for="(item, index) in cates" :key="item.cat_id"
				:class="{active: currentIndex === index}" @click="leftClickHandle(index, item.cat_id)">
				{{item.cat_name}}
			</view>
		</scroll-view>
		
		<scroll-view class="right" scroll-y>
			<view class="right-item" v-for="item in rightList" :key="item.id">
				<image :src="item.img" class="image" @click="previewImg(item.img)"></image>
				<text class="title">{{item.title}}</text>
			</view>
			<text v-if="rightList.length === 0">暂无数据</text>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cates: [],
				currentIndex: 0,
				rightList: [],
				
			}
		},
		onLoad() {
			this.getPicsCate()
		},
		methods: {
			async getPicsCate(){
				const res = await this.$myRequest({
					url:'getImgCategory.json'
				})
				this.cates = res.data.message
				console.log(this.cates)
				this.leftClickHandle(0, this.cates[0].cat_id)
				
			},
			async leftClickHandle(index, id) {
				this.currentIndex = index
				const res = await this.$myRequest({
					url:'getDateByCategory.json'
				})
				this.rightList= res.data.message
				// 模拟数据啦
				if(this.currentIndex & 1) this.rightList = []
			},
			previewImg(imgUrl) {
				console.log(imgUrl)
				const urls = this.rightList.map(item => item.img)
				uni.previewImage({
					urls,
					current: imgUrl,
				})
			}
		}
	}
</script>

<style lang="scss">
	.pics {
		height: 100vh;
		display: flex;
		.left {
			width: 200rpx;
			height: 100%;
			border-right: 1px solid #eee;
			.left-item {
				height: 60px;
				line-height: 60px;
				color: #333;
				text-align: center;
				font-size: 32rpx;
				border-top:1px solid #eee;
			}
			.active {
				background-color: $shop-color;
				color: #fff;
			}
		}
		.right {
			width: 520rpx;
			height: 100%;
			margin: 10rpx auto;
			.right-item{
				padding: 10rpx 0;
				.image {
					width: 520rpx;
					height: 520rpx;
					border-radius: 5px;
				}
				.title {
					font-size: 30rpx;
					line-height: 60rpx;
				}
			}
		}
		
	}
</style>
